package com.guanyong.dao;

import com.guanyong.model.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by mxk on 2017/5/26.
 * 分享日志
 */
public interface KeyBaseJavaDaoMapper {

    @Select("SELECT key_java_zhishu.*,key_base.title  " +
            "FROM key_java_zhishu,key_base WHERE key_java_zhishu.base_id=key_base.id and create_date>=#{dateStr} " +
            " ORDER BY base_id,  create_date ")
    @ResultMap("KeyJavaZhishuResultMap")
    List<KeyJavaZhishuModel> select30(String dateStr);


    @Select("SELECT key_java_zhishu.*,key_base.title  " +
            "FROM key_java_zhishu,key_base WHERE key_java_zhishu.base_id=key_base.id  " +
            " ORDER BY base_id,  create_date ")
    @ResultMap("KeyJavaZhishuResultMap")
    List<KeyJavaZhishuModel> selectAll();

    @Select("SELECT * FROM key_java_zhishu where base_id=#{id} ORDER BY base_id,  create_date ")
    @ResultMap("KeyJavaZhishuResultMap")
    List<KeyJavaZhishuModel> selectByid(@Param("id")int id);


    @Select("SELECT * FROM key_java_zhishu where base_id=#{id} and create_date>=#{dateStr} ORDER BY   create_date DESC LIMIT 30 ")
    @ResultMap("KeyJavaZhishuResultMap")
    List<KeyJavaZhishuModel> selectBy30id(@Param("id")int id,@Param("dateStr")String dateStr);

    int updateById(@Param(value = "record") KeyJavaZhishuModel record);

    @Insert("INSERT INTO key_java_zhishu (base_id,create_date,cur_date,baidu_num,weixin_num,look_num)" +
            " values (#{record.baseId},#{record.createDate},#{record.curDate},#{record" +
            ".baiduNum},#{record.weixinNum},#{record.lookNum})")
    int addZhishu(@Param(value = "record") KeyJavaZhishuModel record);

    @Delete("delete from  key_java_zhishu where id=#{id}")
    Integer delById(@Param("id")int id);
}
